﻿Imports System.Drawing.Printing
Imports System.Drawing.Graphics
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices

Public Class FrmRecapModifDep

#Region "champs"
    Dim position As Integer
    Dim idInt As Integer
    Dim idCli As Integer
    Dim n As Decimal
    Dim v As Decimal
    Public estPlus As Boolean
    Dim idTrav As String
    Dim idTrav2 As String
    Dim qte1, qte2, qte3, qte4, qte5, qte6, qte7, qte8 As Integer
    Dim pr1, pr2, pr3, pr4, pr5, pr6, pr7, pr8, res1, res2, resF As Decimal
    Dim qte9, qte10, qte11, qte12, qte13, qte14, qte15, qte16 As Integer
    Dim pr9, pr10, pr11, pr12, pr13, pr14, pr15, pr16 As Decimal
    Dim macnx As New PPE3.ClassMySqlConnect("853339_depanneur", "071064")
    Dim nbchamps As Integer = 0
#End Region

    Private Sub FrmRecapModifDep_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        FrmTravauxEffectues.Close()
    End Sub

    Private Sub FrmRecapModifDep_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
        Me.Top = 0
        Me.Left = 0
        macnx.Se_Connecter_MySqlServer()
        RafraichirInfo()
        macnx.Se_Deconnecter_MySqlServer()
        Rafraichir()
        lblIdInt.Text = FrmModifDepannage.TextBoxIdIntervention.Text
        idInt = lblIdInt.Text
        idCli = FrmModifDepannage.TextBoxIdClient.Text

        estPlus = True

    End Sub

    Public Sub RafraichirInfo()
        Dim donnees As New Data.DataTable
        macnx.viderVue("TexteInfo1")
        donnees = macnx.Executer_Requete_Select("SELECT TexteInfo FROM InfoFormulaire where NumeroInfo = 1 ", "TexteInfo1")
        nbchamps = donnees.Rows.Count - 1
        macnx.viderVue("TexteInfo2")
        TextBoxInfo.Text = RemplaceSlashApostrophes(macnx.GetChamp_DataTable(donnees, position, 0))
        donnees = macnx.Executer_Requete_Select("SELECT TexteInfo FROM InfoFormulaire where NumeroInfo = 2", "TexteInfo2")
        LabelInfo.Text = RemplaceSlashApostrophes(macnx.GetChamp_DataTable(donnees, position, 0))

    End Sub
    Public Sub Rafraichir()
        Try
            'TextBoxIdClient.Text = MonJeuDeDonnees.Tables("RecapModifDep").Rows(position).Item(0)
            LblNom.Text = FrmModifDepannage.TextBoxNom.Text
            LblPrenom.Text = FrmModifDepannage.TextBoxPrenom.Text
            lblAdresse.Text = FrmModifDepannage.TextBoxAdresse.Text
            lblCp.Text = FrmModifDepannage.TextBoxCP.Text
            LblVille.Text = FrmModifDepannage.TextBoxVille.Text
            LblTelPort.Text = FrmModifDepannage.TextBoxTelPort.Text
            LblTelFixe.Text = FrmModifDepannage.TextBoxTelFixe.Text
            lblEmail.Text = FrmModifDepannage.TextBoxEmail.Text
            lblRenCompAdresse.Text = FrmModifDepannage.TextBoxRenComp.Text
            DateTimePickRecept.Text = FrmModifDepannage.DateTimePickRecept.Text
            DateTimeDebInt.Text = FrmModifDepannage.DateTimeDebInt.Text
            DateTimeFin.Text = FrmModifDepannage.DateTimeFin.Text
            DateTimeLiv.Text = FrmModifDepannage.DateTimeLiv.Text
            'lblIdInt.Text = MonJeuDeDonnees.Tables("RecapModifDep").Rows(position).Item(1)
            TextBoxPb.Text = FrmModifDepannage.TextBoxPb.Text
            TextBoxMateriel.Text = FrmModifDepannage.TextBoxMateriel.Text
            TextBoxTravaux.Text = FrmModifDepannage.TextBoxTravaux.Text

            If FrmModifDepannage.RadioButtonDepannage.Checked = True Then
                RadioButtonDepannage.Checked = True
                RadioButtonFormation.Checked = False
            End If
            If FrmModifDepannage.RadioButtonFormation.Checked = True Then
                RadioButtonDepannage.Checked = False
                RadioButtonFormation.Checked = True
            End If

            If FrmModifDepannage.RadioButtonPortable.Checked = True Then
                RadioButtonPortable.Checked = True
                RadioButtonFixe.Checked = False
                TextBoxAutre.Text = ""
            End If
            If FrmModifDepannage.RadioButtonFixe.Checked = True Then
                RadioButtonPortable.Checked = False
                RadioButtonFixe.Checked = True
                TextBoxAutre.Text = ""
            End If
            If FrmModifDepannage.TextBoxAutre.Text <> "" And FrmModifDepannage.RadioButtonPortable.Checked = False And FrmModifDepannage.RadioButtonPortable.Checked = False Then
                RadioButtonPortable.Checked = False
                RadioButtonFixe.Checked = False
                TextBoxAutre.Text = FrmModifDepannage.TextBoxAutre.Text
            End If

            If FrmModifDepannage.RadioButtonDomicile.Checked = True Then
                RadioButtonDomicile.Checked = True
                RadioButtonAtelier.Checked = False
                RadioButtonDomAtel.Checked = False
            End If

            If FrmModifDepannage.RadioButtonAtelier.Checked = True Then
                RadioButtonDomicile.Checked = False
                RadioButtonAtelier.Checked = True
                RadioButtonDomAtel.Checked = False
            End If
            If FrmModifDepannage.RadioButtonDomAtel.Checked = True Then
                RadioButtonDomicile.Checked = False
                RadioButtonAtelier.Checked = False
                RadioButtonDomAtel.Checked = True
            End If

        Catch ex As InvalidCastException
            MessageBox.Show(ex.Message)
        End Try


    End Sub

#Region "Fonction"
    Public Function RemplaceApostrophesSlash(ByRef unechaine As String) As String
        Dim ch As String
        ch = unechaine.Replace("'", "/")
        Return ch
    End Function


    Public Function RemplaceSlashApostrophes(ByRef unechaine As String) As String
        Dim ch As String
        ch = unechaine.Replace("/", "'")
        Return ch
    End Function

    Public Function RemplaceSlashApostrophesDataTable(ByRef lesdonnees As DataTable)
        Dim nblignes As Integer
        Dim nbcolonnes As Integer
        Dim test As String = ""
        nblignes = lesdonnees.Rows.Count
        nbcolonnes = lesdonnees.Columns.Count
        Dim i, j As Integer
        For i = 0 To nblignes - 1
            For j = 0 To nbcolonnes - 1
                'Attention le replace ne s'applique qu'aux type String : utilisation de la classe de base Object :
                If Object.ReferenceEquals(lesdonnees.Rows(i).Item(j).GetType(), test.GetType()) Then
                    lesdonnees.Rows(i).Item(j) = RemplaceSlashApostrophes(lesdonnees.Rows(i).Item(j))
                End If
            Next
        Next
        Return lesdonnees
    End Function
#End Region

    Private Sub BtnFermer_Click(sender As System.Object, e As System.EventArgs)
        Close()
    End Sub

    Private Sub btnImprimer_Click(sender As System.Object, e As System.EventArgs) Handles btnImprimer.Click
        btnImprimer.Visible = False
        Me.PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
        btnImprimer.Visible = True

    End Sub


    Private Sub BtnCalcul_Click(sender As System.Object, e As System.EventArgs) Handles BtnCalcul.Click

        If lbl1.Text <> "" And lbl2.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text <> "" And lbl4.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2 + qte3 * pr3
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text <> "" And lbl4.Text <> "" And lbl5.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2 + qte3 * pr3 + qte4 * pr4
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text <> "" And lbl4.Text <> "" And lbl5.Text <> "" And lbl6.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2 + qte3 * pr3 + qte4 * pr4 + qte5 * pr5
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text <> "" And lbl4.Text <> "" And lbl5.Text <> "" And lbl6.Text <> "" And lbl7.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2 + qte3 * pr3 + qte4 * pr4 + qte5 * pr5 + qte6 * pr6
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text <> "" And lbl4.Text <> "" And lbl5.Text <> "" And lbl6.Text <> "" And lbl7.Text <> "" And lbl8.Text = "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2 + qte3 * pr3 + qte4 * pr4 + qte5 * pr5 + qte6 * pr6 + qte7 * pr7
        End If
        If lbl1.Text <> "" And lbl2.Text <> "" And lbl3.Text <> "" And lbl4.Text <> "" And lbl5.Text <> "" And lbl6.Text <> "" And lbl7.Text <> "" And lbl8.Text <> "" Then
            TextBoxRes1.Text = qte1 * pr1 + qte2 * pr2 + qte3 * pr3 + qte4 * pr4 + qte5 * pr5 + qte6 * pr6 + qte7 * pr7 + qte8 * pr8
        End If

        If lbl9.Text <> "" And lbl10.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text <> "" And lbl12.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10 + qte11 * pr11
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text <> "" And lbl12.Text <> "" And lbl13.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10 + qte11 * pr11 + qte12 * pr12
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text <> "" And lbl12.Text <> "" And lbl13.Text <> "" And lbl14.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10 + qte11 * pr11 + qte12 * pr12 + qte13 * pr13
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text <> "" And lbl12.Text <> "" And lbl13.Text <> "" And lbl14.Text <> "" And lbl15.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10 + qte11 * pr11 + qte12 * pr12 + qte13 * pr13 + qte14 * pr14
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text <> "" And lbl12.Text <> "" And lbl13.Text <> "" And lbl14.Text <> "" And lbl15.Text <> "" And lbl16.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10 + qte11 * pr11 + qte12 * pr12 + qte13 * pr13 + qte14 * pr14 + qte15 * pr15
        End If
        If lbl9.Text <> "" And lbl10.Text <> "" And lbl11.Text <> "" And lbl12.Text <> "" And lbl13.Text <> "" And lbl14.Text <> "" And lbl15.Text <> "" And lbl16.Text = "" Then
            TextBoxRes2.Text = qte9 * pr9 + qte10 * pr10 + qte11 * pr11 + qte12 * pr12 + qte13 * pr13 + qte14 * pr14 + qte15 * pr15 + qte16 * pr16
        End If

        If lbl1.Text <> "" And lbl9.Text <> "" Then
            res1 = TextBoxRes1.Text
            res2 = TextBoxRes2.Text
            TextBoxPrix.Text = res1 + res2
        End If
        If lbl1.Text <> "" And lbl9.Text = "" Then
            res1 = TextBoxRes1.Text
            TextBoxPrix.Text = res1
        End If
        If lbl1.Text = "" And lbl9.Text <> "" Then
            res2 = TextBoxRes2.Text
            TextBoxPrix.Text = res2
        End If
    End Sub

#Region "textchanged"

    Private Sub lbl101_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl101.TextChanged
        qte1 = lbl101.Text
    End Sub

    Private Sub lbl102_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl102.TextChanged
        pr1 = lbl102.Text
    End Sub

    Private Sub lbl201_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl201.TextChanged
        qte2 = lbl201.Text
    End Sub

    Private Sub lbl202_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl202.TextChanged
        pr2 = lbl202.Text
    End Sub

    Private Sub lbl301_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl301.TextChanged
        qte3 = lbl301.Text
    End Sub

    Private Sub lbl302_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl302.TextChanged
        pr3 = lbl302.Text
    End Sub

    Private Sub lbl401_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl401.TextChanged
        qte4 = lbl401.Text
    End Sub

    Private Sub lbl402_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl402.TextChanged
        pr4 = lbl402.Text
    End Sub

    Private Sub lbl501_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl501.TextChanged
        qte5 = lbl501.Text
    End Sub

    Private Sub lbl502_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl502.TextChanged
        pr5 = lbl502.Text
    End Sub

    Private Sub lbl601_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl601.TextChanged
        qte6 = lbl601.Text
    End Sub

    Private Sub lbl602_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl602.TextChanged
        pr6 = lbl602.Text
    End Sub

    Private Sub lbl701_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl701.TextChanged
        qte7 = lbl701.Text
    End Sub

    Private Sub lbl702_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl702.TextChanged
        pr7 = lbl702.Text
    End Sub

    Private Sub lbl801_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl801.TextChanged
        qte8 = lbl801.Text
    End Sub

    Private Sub lbl802_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl802.TextChanged
        pr8 = lbl802.Text
    End Sub


    Private Sub lbl91_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl91.TextChanged
        qte9 = lbl91.Text
    End Sub

    Private Sub lbl92_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl92.TextChanged
        pr9 = lbl92.Text
    End Sub

    Private Sub lbl1001_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl1001.TextChanged
        qte10 = lbl1001.Text
    End Sub

    Private Sub lbl1002_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl1002.TextChanged
        pr10 = lbl1002.Text
    End Sub

    Private Sub lbl111_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl111.TextChanged
        qte11 = lbl111.Text
    End Sub

    Private Sub lbl112_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl112.TextChanged
        pr11 = lbl112.Text
    End Sub

    Private Sub lbl121_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl121.TextChanged
        qte12 = lbl121.Text
    End Sub

    Private Sub lbl122_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl122.TextChanged
        pr12 = lbl122.Text
    End Sub

    Private Sub lbl131_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl131.TextChanged
        qte13 = lbl131.Text
    End Sub

    Private Sub lbl132_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl132.TextChanged
        pr13 = lbl132.Text
    End Sub

    Private Sub lbl141_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl141.TextChanged
        qte14 = lbl141.Text
    End Sub

    Private Sub lbl142_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl142.TextChanged
        pr14 = lbl142.Text
    End Sub

    Private Sub lbl151_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl151.TextChanged
        qte15 = lbl151.Text
    End Sub

    Private Sub lbl152_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl152.TextChanged
        pr15 = lbl152.Text
    End Sub

    Private Sub lbl161_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl161.TextChanged
        qte16 = lbl161.Text
    End Sub

    Private Sub lbl162_TextChanged(sender As System.Object, e As System.EventArgs) Handles lbl162.TextChanged
        pr16 = lbl162.Text
    End Sub

#End Region

End Class
